let aBox = document.querySelector('.logout');
let init = document.querySelector('.init');
let titlebox = document.querySelectorAll('.nav>li>a');
let twoTitle = document.querySelectorAll('.nav ul li a');

//判断是否有令牌
axios.get('/student/list')
.then(res =>{
    console.log(res);
})
//点击退出
aBox.querySelector('a').addEventListener('click',()=>{
    let i = confirm('确定退出？')
    if(i){
        localStorage.removeItem('tokens')
        location.href = './login.html'
    }
})

//初始化数据
init.addEventListener('click', () => {
    axios.get('/init/data', {
        headers: { Authorization: localStorage.getItem('tokens') }
    })
        .then(res => {
            console.log(res);
        })
})

//实现点击标题做操作
//点击一级标题出现的效果有：一级标题上的箭头旋转和展开二级标题。在点击旋转箭头和隐藏二级标题
titlebox.forEach(arr=>{
    arr.addEventListener('click',function(){
        //实现箭头旋转切换
        this.querySelector('.toggle').classList.toggle('toggles')
        //实现二级标题的显示与隐藏的切换
        this.nextElementSibling.classList.toggle('show')
    })
})

//实现点击二级标题显示相对应的内容
twoTitle.forEach(arr=>{
    arr.addEventListener('click',function(){
        document.querySelector('.active').classList.remove('active')
        this.classList.add('active')
    })
})